/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package service.publics.impl;

import dao.publics.SupplierDao;
import java.util.List;
import java.util.Map;
import model.publics.Supplier;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;
import service.publics.SupplierService;
import utility.NameValueList;
import utility.StringUtils;

/**
 *
 * @author jay
 */
@Service("supplierService")
@Transactional(readOnly=true)
public class SupplierServiceImpl implements SupplierService {
    
    //avoid LazyInitializationException 
    String mainQuery = "select supplier from Supplier supplier left join fetch supplier.suprincipal suprincipal";
        
    @Autowired private SupplierDao supplierDao;

    @Transactional(readOnly=false)
    @Override
    public boolean save(Supplier product) {
        return supplierDao.save(product);
    }

    @Transactional(readOnly=false)
    @Override
    public boolean delete(Supplier product) {
        return supplierDao.delete(product);
    }

    @Override
    public Supplier getSupplier(int id) {
        return supplierDao.getById(id);
    }

    @Override
    public List<Supplier> getAll(int start, int num, String params, String orderBy) {
        return supplierDao.getAll(start, num, params, orderBy);
    }

    @Override
    public Supplier getSupplier(String kode) {
        return supplierDao.getByKode("kode", kode);
    }

    @Override
    public List<Supplier> getAll(int start, int num, Map<NameValueList, Object> params) {
        String query = mainQuery+StringUtils.getFilter(params);
        return supplierDao.getAll(start, num, query);
    }
   
    
}
